<template>
  <div class="ScoreRecord">
    <ScoreHeader />
    <CardHeader />
    <van-cell-group inset class="lists">
      <van-list
        v-model="loading"
        :finished="finished"
        finished-text="没有更多了"
        @load="onLoad"
        offset="50"
      >
        <van-cell
          v-for="item in PointRecordList"
          :key="item.cpointId"
          is-link
          @click="toDetail(item.orderId)"
        >
          <template #title>
            <div class="item">
              <div class="item-pic"><img :src="item.defaultImages" /></div>
              <div class="custom">
                <div class="custom-title">
                  <van-tag
                    v-if="item.orderStatus == '8'"
                    class="ico"
                    color="#C8C8C8"
                    >失败</van-tag
                  >
                  <van-tag v-else type="primary" class="ico" color="#00BDAE"
                    >成功</van-tag
                  >
                  {{ item.goodsName }}
                </div>
                <div class="custom-time">{{ item.createTime }}</div>
              </div>
            </div>
          </template>
          <template #right-icon>
            <span class="icon"><van-icon name="arrow" /></span>
          </template>
        </van-cell>
      </van-list>
    </van-cell-group>
  </div>
</template>

<script>
import ScoreHeader from "./components/header.vue";
import CardHeader from "./components/card-header.vue";
export default {
  name: "ScoreRecord",
  components: {
    ScoreHeader,
    CardHeader,
  },
  data() {
    return {
      PointRecordList: [],
      isPages: false,
      loading: false,
      moreLoading: false,
      finished: false,
      dataValue: {
        first: 0,
        limit: 10,
      },
    };
  },
  created() {},
  methods: {
    onLoad(mode = "more") {
      // if (this.isPages) {
      //   return (this.finished = true);
      // }
      this.dataValue.first++;
      this.getData(mode);
    },
    toDetail(orderId) {
      let query = {
        orderId,
      };
      this.$router.push({ path: "/exchangeDetails", query });
    },
    getData(mode) {
      this.$http
        .get(
          `/api/shop/order/query?first=${this.dataValue.first}&limit=${this.dataValue.limit}`
        )
        .then((res) => {
          // this.PointRecordList = res.data;
          if (res.code == "0") {
            if (mode == "more") {
              this.PointRecordList = [...this.PointRecordList, ...res.data];
            } else {
              this.PointRecordList = res.data;
            }
            if (
              (this.PointRecordList && !this.PointRecordList.length) ||
              !res.data.length ||
              res.data.length != 10
            ) {
              this.finished = true;
              // this.isPages = true
            }
          }
          setTimeout(() => {
            this.loading = false;
            this.moreLoading = false;
          }, 1000);
        });
    },
  },
};
</script>
<style scoped lang="less">
.lists {
  margin: 0 18px;
  border-radius: 8px;
  overflow: hidden;
  .icon {
    display: flex;
    align-items: center;
    color: #969799;
    font-size: 16px;
  }
  .item {
    display: flex;
    &-pic {
      img {
        width: 40px;
        height: 40px;
        border: 1px solid #ebedf0;
        border-radius: 6px;
      }
    }
    .custom {
      flex: 1;
      padding-left: 8px;
      &-title {
        display: -webkit-box;
        vertical-align: middle;
        overflow: hidden;
        text-overflow: ellipsis;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 1;
        .ico {
          margin-right: 2px;
        }
      }
      &-time {
        font-size: 12px;
        color: #999;
      }
    }
  }
}
</style>
